export default {
    name: "Onlinedevicelist",
    data() {
        return {
            currentPage: 1,
            pagesize: 5,
            total: 0,
            onlinedevicelistData: [],
            height: '600',
            searchForm: {
                deviceId: '',
                deviceName: '',
                deviceType: ''
            },
            TypeData: [],
            multipleSelection: [],
        };
    },
    computed: {
        offset: function () {
            return (this.currentPage - 1) * this.pagesize;
        }
    },
    watch: {

    },
    created() {
        this.selectType();
        this.initOnlineList();
    },
    mounted() { },
    methods: {
        //获取设备过滤名
        selectType() {
            this.$http.get("/deviceTypeController/queryAllDeviceType")
                .then((res) => {
                    if (res.status == 200) {
                        this.TypeData = res.data;
                    }
                }).catch((err) => {
                console.log(err);
            });
        },
        initOnlineList(){
            var listParamsObj = {
                limit: this.pagesize,
                offset: this.offset,
                deviceStatus:true,
                deviceName: this.searchForm.deviceName,
                deviceId: this.searchForm.deviceId,
                deviceModelName: this.searchForm.deviceType,
            }
            this.$http.post('/deviceCommonInfoController/devicesPage', this.qs.stringify(listParamsObj))
                .then((res) => {
                    if (res.status == 200) {
                        if(res.data != null && res.total != null){
                            this.onlinedevicelistData = res.data;
                            this.total = res.total;
                        } else if(res.data == null && res.total == null){
                            this.onlinedevicelistData = [];
                            this.total = 0;
                            this.$message.error(res.msg)
                        }
                    }
                    return false;
                }).catch((err) => {
                console.log(err);
            });
        },
        rowClick(row){
            this.$router.push({
                name: "Onliedevicedetail",
                params: {
                    rowId: row.rowKey,
                    row: row,
                }
            });
        },
        handleClickRow() {
            if (this.multipleSelection.length == 0) {
                this.$message.error("请至少选择一个用户");
                return false;
            } else if (this.multipleSelection.length > 9) {
                this.$message.error("选择的设备不能超过9个。");
                return false;
            } else {
                var rowKeyData = [];
                var deviceTypeData = [];
                this.multipleSelection.forEach(function (val, idx) {
                    console.log(val);
                    rowKeyData.push(val.rowKey);
                    deviceTypeData.push(val.deviceType)
                });
                var rowKey = rowKeyData
                var deviceType = deviceTypeData
                console.log(rowKey);
                console.log(deviceType);
                this.$router.push({
                    name: 'Onlinepreview',
                    params: {
                        rowKeyData: rowKey,
                        deviceTypeData:deviceType
                    },
                });
            }
        },
        toggleSelection(rows) {
            if (rows) {
                rows.forEach(row => {
                    this.$refs.multipleSelection.toggleRowSelection(row);
                });
            } else {
                this.$refs.multipleTable.clearSelection();
            }
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        handleSizeChange(val) {
            this.pagesize = val;
            this.initOnlineList();
        },
        handleCurrentChange(val) {
            this.currentPage = val;
            this.initOnlineList();
        }
    }
};